"use strict";
const common_vendor = require("../../../common/vendor.js");
const api_news_index = require("../../../api/news/index.js");
const config_app = require("../../../config/app.js");
if (!Array) {
  const _easycom_up_tabs2 = common_vendor.resolveComponent("up-tabs");
  const _easycom_up_empty2 = common_vendor.resolveComponent("up-empty");
  const _easycom_up_toast2 = common_vendor.resolveComponent("up-toast");
  (_easycom_up_tabs2 + _easycom_up_empty2 + _easycom_up_toast2)();
}
const _easycom_up_tabs = () => "../../../node-modules/uview-plus/components/u-tabs/u-tabs.js";
const _easycom_up_empty = () => "../../../node-modules/uview-plus/components/u-empty/u-empty.js";
const _easycom_up_toast = () => "../../../node-modules/uview-plus/components/u-toast/u-toast.js";
if (!Math) {
  (_easycom_up_tabs + newsListItem + _easycom_up_empty + _easycom_up_toast)();
}
const newsListItem = () => "../../../components/newsListItem/newsListItem.js";
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  __name: "index",
  setup(__props) {
    const uToastRef = common_vendor.ref(null);
    const data = common_vendor.reactive({
      news: {
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          type: 1
        },
        current: 0,
        list: [],
        total: 0,
        request: [api_news_index.integritylistPage]
      }
    });
    const { news } = common_vendor.toRefs(data);
    common_vendor.onLoad((options) => {
      initNews();
    });
    const initNews = () => {
      common_vendor.index.showLoading({
        title: "加载中",
        mask: true
      });
      news.value.request[0](news.value.queryParams).then((res) => {
        common_vendor.index.hideLoading();
        const { data: data2 } = res;
        data2.records = data2.records ?? [];
        news.value.list = [...news.value.list, ...data2.records];
        news.value.total = data2.total;
        common_vendor.index.stopPullDownRefresh();
      }).catch((err) => {
        news.value.list = [];
        uToastRef.value.show({
          type: "error",
          message: err
        });
      });
    };
    const scanNewsDetail = (item) => {
      common_vendor.index.navigateTo({
        url: `/subPages/crowd/news/detail?newsId=${item.id}&newsType=${news.value.current}`
      });
    };
    common_vendor.onReachBottom(() => {
      let allTotal = news.value.queryParams.pageNum * news.value.queryParams.pageSize;
      if (allTotal < news.value.total) {
        news.value.queryParams.pageNum++;
        initNews();
      } else {
        uToastRef.value.show({
          type: "info",
          message: "暂无更多数据"
        });
        return;
      }
    });
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.o((item, index) => {
          common_vendor.unref(news).current = index;
          common_vendor.unref(news).list = [];
          common_vendor.unref(news).queryParams = {
            pageNum: 1,
            pageSize: 10,
            type: index + 1
          };
          initNews();
        }),
        b: common_vendor.p({
          list: [{
            name: "党纪知识"
          }, {
            name: "典型案例"
          }, {
            name: "廉政漫画"
          }]
        }),
        c: common_vendor.unref(news).list.length
      }, common_vendor.unref(news).list.length ? {
        d: common_vendor.f(common_vendor.unref(news).list, (item, index, i0) => {
          return {
            a: "1a128fb9-1-" + i0,
            b: common_vendor.p({
              newsTitle: item.title,
              newsTime: item.createTime ? common_vendor.unref(common_vendor.dayjs)(item.createTime).format("YYYY-MM-DD") : "",
              newsImg: common_vendor.unref(config_app.imgPrefix) + item.imgUrl
            }),
            c: index,
            d: common_vendor.o(($event) => scanNewsDetail(item), index)
          };
        })
      } : {
        e: common_vendor.p({
          mode: "history",
          text: "暂无数据",
          icon: "http://cdn.uviewui.com/uview/empty/history.png"
        })
      }, {
        f: common_vendor.sr(uToastRef, "1a128fb9-3", {
          "k": "uToastRef"
        })
      });
    };
  }
});
wx.createPage(_sfc_main);
